﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Microsoft.Practices.ServiceLocation;
using Subfaculty.Common.Interfaces.Services;
using Subfaculty.WebApplication.ViewModels;

namespace Subfaculty.WebApplication.Controllers
{
    public class AllocationController : Controller
    {
    	private IDepartmentRepository _departmentRepository;
    	private IStudyYearRepository _studyYearRepository;
    	//
        // GET: /Allocation/
		public AllocationController()
		{
			_studyYearRepository = ServiceLocator.Current.GetInstance<IStudyYearRepository>();
			_departmentRepository = ServiceLocator.Current.GetInstance<IDepartmentRepository>();
		}
        public ActionResult Index()
        {
        	var all = new AllocationViewModel()
        	          	{
        	          		StudyArea = "230100 Информатика и вычислительная техника Вычислительные машины и системы",
        	          		StudyYear = "2009 - 2010",

							AllocationItems = new List<AllocationItemViewmodel>
			                   		{	                   	
										  		new AllocationItemViewmodel()
									                                 			{
									                                 				Department = "ЭВМиС",
									                                 				Discipline = "ТА",
									                                 				Semester = 2,
									                                 				HoursLecture = 54,
									                                 				HoursLab = 18,
									                                 				HoursPractice = 0,
									                                 				HoursSRS = 36,
									                                 				EStudyControl = "Э",
									                                 				ETypeSRS = "С",
									                                 				StudyGroups = "ЭВМ-5.1"
									                                 			}
									}
        	          	};
			return View(all);
        }

		[HttpPost]
		public ActionResult _GetDepartment(string text)
		{
			var dep = _departmentRepository.GetAll();
				return new JsonResult
				{
					Data = new SelectList(dep, "Id", "Abbreviation")
				};
			
		}

		[HttpPost]
		public ActionResult _GetYears(string text)
		{
			var years = _studyYearRepository.GetAll();
				return new JsonResult
				{
					Data = new SelectList(years, "Id", "StartDate")
				};
			
		}

		public ActionResult LoadAtoms()
		{
			var all = new List<LoadAtomsViewModel>()
			{
				new LoadAtomsViewModel()
					{
						TypeLoadAtom = "Лекция",
 						Hours = 54,
						Groups = "ЭВМ-5.1"
					},
					
					new LoadAtomsViewModel()
					{
						TypeLoadAtom = "Лабораторная работа",
 						Hours = 18,
						Groups = "ЭВМ-5.1 - 1"
					},
					new LoadAtomsViewModel()
					{
						TypeLoadAtom = "Лабораторная работа",
 						Hours = 18,
						Groups = "ЭВМ-5.1 - 2"
					},
					new LoadAtomsViewModel()
					{
						TypeLoadAtom = "Семестровая",
 						Hours = 19,
						Groups = "ЭВМ-5.1"
					},
					new LoadAtomsViewModel()
					{
						TypeLoadAtom = "СРС",
 						Hours = 8.5,
						Groups = "ЭВМ-5.1"
					},
					new LoadAtomsViewModel()
					{
						TypeLoadAtom = "Консультация к экзамену",
 						Hours = 2,
						Groups = "ЭВМ-5.1"
					},
					new LoadAtomsViewModel()
					{
						TypeLoadAtom = "Экзамен",
 						Hours = 5.7,
						Groups = "ЭВМ-5.1"
					},
			};
			return View(all);
		}

    }

	public class LoadAtomsViewModel
	{
		[ScaffoldColumn(false)]
		public int Id { get; set; }
		[Display(Name = "Вид нагрузки")]
		public string TypeLoadAtom { get; set; }
		[Display(Name = "Часы")]
		public double Hours { get; set; }
		[Display(Name = "Группы/подгруппы")]
		public string Groups { get; set; }
	}
}
